# Create your views here. 
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.contrib.auth import authenticate, login, logout
from django.template.loader import get_template
from django.template import Template, Context
from django.http import HttpResponseRedirect
from PSM.PSMDatabase.models import *

def teacher_form(request):
    return render_to_response('teacher_form.html')

def teacher(request):
    #if 'user' in request.GET and request.GET['user'] and 'password' in request.GET and request.GET['password']
    username = request.GET['username']
    password = request.GET['password']  
    user = authenticate(username=username, password=password)
    if user is not None:
    	if user.is_active:
                login(request, user)
                url = request.get_host()
    		t = get_template('teacher_main.html')
    		html = t.render(Context({'URL': url}))
    		return HttpResponse(html)         	
    	else:
        	return render_to_response('teacher_form_err.html')
    else:
    	return render_to_response('teacher_form_err.html')



def addStudent_form(request):
     if not request.user.is_authenticated():
	return render_to_response('teacher_form.html')
     url = request.get_host()
     t = get_template('add_student_form.html')
     html = t.render(Context({'URL': url}))
     return HttpResponse(html)
      
        
   
    


def addAllScore_form(request):
    if not request.user.is_authenticated():
	return render_to_response('teacher_form.html')
    url = request.get_host()
    t = get_template('add_all_score_form.html')
    html = t.render(Context({'URL': url}))
    return HttpResponse(html)



def addLabScore_form(request):
    if not request.user.is_authenticated():
	return render_to_response('teacher_form.html')
    url = request.get_host()
    t = get_template('add_lab_score_form.html')
    html = t.render(Context({'URL': url}))
    return HttpResponse(html)



def addMidScore_form(request):
    if not request.user.is_authenticated():
	return render_to_response('teacher_form.html')
    url = request.get_host()
    t = get_template('add_mid_score_form.html')
    html = t.render(Context({'URL': url}))
    return HttpResponse(html)

def addFinalScore_form(request):
    if not request.user.is_authenticated():
	return render_to_response('teacher_form_err.html')
    url = request.get_host()
    t = get_template('add_final_score_form.html')
    html = t.render(Context({'URL': url}))
    return HttpResponse(html)


def calculateGrade(request):
    if not request.user.is_authenticated():
	return render_to_response('teacher_form.html')
    url = request.get_host()
    t = get_template('calculation_grade_form.html')
    html = t.render(Context({'URL': url}))
    return HttpResponse(html)



def showGrade(request):
    if not request.user.is_authenticated():
	return render_to_response('teacher_form_err.html')
    url = request.get_host()
    t = get_template('show_grade_form.html')
    html = t.render(Context({'URL': url}))
    return HttpResponse(html)


def uploadFile(request):
    if not request.user.is_authenticated():
	return render_to_response('teacher_form.html')
    url = request.get_host()
    t = get_template('upload_file.html')
    html = t.render(Context({'URL': url}))
    return HttpResponse(html)



def sendGrade(request):
    if not request.user.is_authenticated():
	return render_to_response('teacher_form.html')
    url = request.get_host()
    t = get_template('sent_grade_form.html')
    html = t.render(Context({'URL': url}))
    return HttpResponse(html)


def logout_view(request):
    logout(request)
    return render_to_response('teacher_form.html')


